package com.esoon.service.impl;

import com.esoon.dao.CosTenantDao;
import com.esoon.dao.CsrLeaveMessageDao;
import com.esoon.entity.CosTenant;
import com.esoon.entity.CsrLeaveMessage;
import com.esoon.entity.MyTenant;
import com.esoon.service.CsrLeaveMessageService;
import com.esoon.service.CsrServiceRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @ClassName CsrLeaveMessageServiceImpl
 * @Description TODO 插入成功返回0 插入失败返回500
 * @Author 2020/10/15 15:29
 * @Version 1.0
 **/
@Service
public class CsrLeaveMessageServiceImpl implements CsrLeaveMessageService {
    private static final Logger logger;

    static {
        logger = LoggerFactory.getLogger(CsrLeaveMessageServiceImpl.class);
    }
    @Resource
    private CsrLeaveMessageDao csrLeaveMessageDao;
    @Resource
    private CosTenantDao cosTenantDao;
    @Override
    public String insert(String AD_CUST_ANI, String AD_SYS_MSGPATH,String tenantCode,String LM_NODE) {
        MyTenant myTenant = cosTenantDao.selectByTenantCode(tenantCode);
        Integer ttId = myTenant.getTtId();
        String ttName = myTenant.getTtName();
        CsrLeaveMessage csrLeaveMessage = new CsrLeaveMessage();
        csrLeaveMessage.setLmPhone(AD_CUST_ANI);
        csrLeaveMessage.setLmTime(new Date());
        csrLeaveMessage.setLmPathName(AD_SYS_MSGPATH);
        csrLeaveMessage.setLmState("待回呼");
        csrLeaveMessage.setCreateTime(new Date());
        csrLeaveMessage.setTenantId(ttId);
        csrLeaveMessage.setTenantName(ttName);
        csrLeaveMessage.setLmNode(LM_NODE);
        try{
            csrLeaveMessageDao.insert(csrLeaveMessage);
            logger.info("留言回写表插入成功，参数如下 :" + csrLeaveMessage.toString());
            return "1";
        }catch (Exception e){
            logger.error("留言回写表插入失败，错误信息如下 :" + e.toString());
            return "500";
        }
    }
}
